Skip to content

⚗️ Angular- Add error handling integration#4358

Merged
rgaignault merged 8 commits into
mainfrom
romanG/angular-error-on-router
Mar 25, 2026
Merged

⚗️ Angular- Add error handling integration#4358
rgaignault merged 8 commits into
mainfrom
romanG/angular-error-on-router

Conversation

@rgaignault
Copy link
Copy Markdown
Contributor

@rgaignault rgaignault commented Mar 19, 2026

Motivation

Add error handling to @datadog/browser-rum-angular, complementing the router integration from #4315.

When an Angular error occurs, without this integration it shows up as an anonymous unhandled error via window.onerror. With this integration, errors are properly categorized as handled errors with framework: "angular" context and a handling_stack.

Changes

New exports:

  • provideDatadogErrorHandler() — Angular provider that replaces the default ErrorHandler, reports errors to RUM then delegates to super.handleError()
  • addAngularError(error) — standalone function for users with custom error handlers

Implementation:

  • Uses the addError plugin API (same pattern as React's addReactError)
  • Captures handling_stack via createHandlingStack('angular error')

Tests:

  • Unit tests for addAngularError, provideDatadogErrorHandler, and dd_context merging
  • E2E tests for error reporting and dd_context support

RFC: https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/6387532503

@rgaignault rgaignault requested a review from a team as a code owner March 19, 2026 12:33
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented Mar 19, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 176.56 KiB 176.56 KiB 0 B 0.00%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 27.46 KiB 27.46 KiB 0 B 0.00%
Logs 56.88 KiB 56.88 KiB 0 B 0.00%
Rum Slim 132.19 KiB 132.19 KiB 0 B 0.00%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0047 0.0038 -19.15%
RUM - add action 0.0135 0.0126 -6.67%
RUM - add error 0.0127 0.0126 -0.79%
RUM - add timing 0.0027 0.0025 -7.41%
RUM - start view 0.0122 0.0119 -2.46%
RUM - start/stop session replay recording 0.0007 0.0006 -14.29%
Logs - log message 0.0165 0.0142 -13.94%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.10 KiB 26.51 KiB -601 B
RUM - add action 52.91 KiB 51.97 KiB -970 B
RUM - add timing 26.27 KiB 26.40 KiB +130 B
RUM - add error 55.90 KiB 54.85 KiB -1.05 KiB
RUM - start/stop session replay recording 25.02 KiB 26.36 KiB +1.34 KiB
RUM - start view 462.96 KiB 461.98 KiB -1009 B
Logs - log message 44.96 KiB 45.16 KiB +201 B

🔗 RealWorld

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Mar 19, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 77.32% (+0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 67fc656 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from 5d02daf to cc41070 Compare March 19, 2026 13:02
@rgaignault rgaignault marked this pull request as draft March 19, 2026 13:06
@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from cc41070 to 7284bc7 Compare March 19, 2026 13:10
@rgaignault rgaignault marked this pull request as ready for review March 19, 2026 13:11
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7284bc7112

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rum-angular/src/domain/error/addAngularError.ts Outdated
@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from 7284bc7 to a77040b Compare March 19, 2026 13:29
@rgaignault rgaignault changed the title ✨ Angular- Add error handling integration ⚗️ Angular- Add error handling integration Mar 19, 2026
@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from a77040b to 7cd6e04 Compare March 19, 2026 13:47
Comment thread packages/rum-angular/src/domain/error/provideDatadogErrorHandler.ts Outdated
Comment thread packages/rum-angular/src/domain/error/provideDatadogErrorHandler.spec.ts Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question: ‏Why do you need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angular/core uses globalThis directly (without a guard), and that throw a reference error on chrome 63

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting :)
Out of curiosity, do you have the reference in @angular/core where it’s used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any other idea to handle this ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum weird, error comes from afterAll.
Anyway, you could try this on the test related to the error:

 .withHead(html`
      <script>
        if (typeof globalThis === 'undefined') {
          window.globalThis = window
        }
      </script>
    `)

@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from a369d88 to 37da729 Compare March 19, 2026 15:21
Comment thread packages/rum-angular/src/domain/error/addAngularError.ts
Comment thread packages/rum-angular/src/domain/error/provideDatadogErrorHandler.spec.ts Outdated
Copy link
Copy Markdown
Contributor

@BeltranBulbarellaDD BeltranBulbarellaDD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from romanG/angular-integration to main March 24, 2026 09:38
@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from 37da729 to 55c21af Compare March 24, 2026 10:16
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum weird, error comes from afterAll.
Anyway, you could try this on the test related to the error:

 .withHead(html`
      <script>
        if (typeof globalThis === 'undefined') {
          window.globalThis = window
        }
      </script>
    `)

@rgaignault rgaignault force-pushed the romanG/angular-error-on-router branch from 8ce41d9 to 35cc95d Compare March 25, 2026 10:06
@rgaignault rgaignault merged commit 7607f68 into main Mar 25, 2026
21 checks passed
@rgaignault rgaignault deleted the romanG/angular-error-on-router branch March 25, 2026 11:12
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants